package priv.bruce.servlet;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson.JSON;

import priv.bruce.entry.MovieInfo;
import priv.bruce.service.MovieInfoService;

public class DeleteMovieByIdServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	
	private MovieInfoService movieInfoService = new MovieInfoService();

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		response.setContentType("application/json;charset=utf-8");
		int id = Integer.valueOf(request.getParameter("movie_id"));
		try {
			List<MovieInfo> findById = movieInfoService.findById(id);
			if (findById.size() == 1) {
				int deleteById = movieInfoService.deleteById(id);
				System.out.println("影响行数："+deleteById);
				response.getWriter().append(JSON.toJSONString(deleteById));
			}else {
				response.getWriter().append(JSON.toJSONString(-1));
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
